<template>
  <h1>我是登录页面</h1>
  <div>
    {{msg}}
    <p>账号：<input type="text" v-model.trim="username"></p>
    <p>密码：<input type="text" v-model.trim="password"></p>
    <p>
      <button @click="logined">登录</button>
    </p>
  </div>

</template>

<script>
//import xxx from '@/service/xxx';
import axios from "axios";
export default {

  name: "login",

  data() {
    return {
      username: "yykk",
      password: "123456"
    }
  },

  created() {

  },

  methods: {
    logined(){
      // 1: 获取用户输入的账号和密码
      let username = this.username;
      let password = this.password;
      // 2: 发起异步请求
      axios.post("/admin/v1/auth/login/pwd", {username, password}).then(res => {
        console.log(res)
        if (res.data.status == 200) {
          // 3: 获取服务器段返回的数据信息
          const {token, userId,username,nickname} = res.data.data;
          // 4: 把服务器段信息放入到session中  $store
          sessionStorage.setItem("token", token);
          sessionStorage.setItem("nickname", nickname);
          sessionStorage.setItem("username", username);
          sessionStorage.setItem("userId", userId);
          // 5: 跳转后台首页
          this.$router.push("/")
        }
      }).catch(err => {
        console.error("登录失败!!!", err)
      })
    }
  }

}
</script>

<style scoped>

</style>